package Servlet;

import javaBean.Message;
import useBean.MessageDB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * <p>Title: DeleteMessageServlet</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2021/12/21 23:19
 */
@WebServlet("/ModifyMessageServlet")
public class ModifyMessageServlet extends HttpServlet{
    /**
     * @see HttpServlet#doGet(HttpServletRequest, HttpServletResponse) (HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String url ="/modify.jsp";
        Message message = null;
        try {
            message = MessageDB.selectMessagem(request.getParameter("mid"));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        request.setAttribute("title" , message.gettitle() );
        request.setAttribute("mid" , request.getParameter("mid") );
        request.setAttribute("textArea" , message.getcontext() );
        request.getServletContext().getRequestDispatcher(url).forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String action = request.getParameter("action");
        String url ="/modify.jsp";

        Message message = null;
        try {
            message = MessageDB.selectMessagem(request.getParameter("mid"));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        request.setAttribute("title" , message.gettitle() );
        request.setAttribute("textArea" , message.getcontext() );
        request.getServletContext().getRequestDispatcher(url).forward(request, response);
    }


}
